import time
class BasePage:
    def __init__(self, driver):
        self.driver = driver

    def open_page(self, url=None):
        if isinstance(url, str):
            self.driver.get(url)
        else:
            print("BasePage:self.url=", self.url)
            self.driver.get(self.url)


    def by_id(self, id_):
        return self.driver.find_element_by_id(id_)

    def by_class(self, class_name):
        return self.driver.find_element_by_class_name(class_name)

    def by_name(self, name):
        return self.driver.find_element_by_class_name(name)

    def by_css(self, css):
        return self.driver.find_element_by_css_selector(css)

    def by_xpath(self, xpath):
        return self.driver.find_element_by_xpath(xpath)

    def get_title(self):
        return self.driver.title

    def get_element_text(self, xpath):
        """
            获取页面元素上的text值
        """
        return self.by_xpath(xpath).text

    def exec_js(self, js):
        self.driver.execute_script(js)
